﻿namespace WFBot.Data
{
    using System.Data.EntityClient;
    using System.Data.Objects;
    using System.Diagnostics;

    using Framework.Domain;

    public class Database : ObjectContext
    {
        private IObjectSet<Question> _questions;
        private IObjectSet<Visitor> _visitors;
        private IObjectSet<Operator> _operators;

        public Database(EntityConnection connection)
            : base(connection)
        {
            ContextOptions.LazyLoadingEnabled = true;
            ContextOptions.ProxyCreationEnabled = true;
        }

        public IObjectSet<Question> Questions
        {
            [DebuggerStepThrough]
            get
            {
                return _questions ?? (_questions = ObjectSet<Question>());
            }
        }

        public IObjectSet<Visitor> Visitors
        {
            [DebuggerStepThrough]
            get
            {
                return _visitors ?? (_visitors = ObjectSet<Visitor>());
            }
        }

        public IObjectSet<Operator> Operators
        {
            [DebuggerStepThrough]
            get
            {
                return _operators ?? (_operators = ObjectSet<Operator>());
            }
        }


        public virtual IObjectSet<TEntity> ObjectSet<TEntity>() where TEntity : class, IEntity
        {
            return CreateObjectSet<TEntity>();
        }

        public virtual void Commit()
        {
            SaveChanges();
        }
    }
}